﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Data.Dynamics
{
    [Jemgine.Engine.Category("Primitive"), Jemgine.Engine.Node]
    public class GearJoint : Dynamic
    {
        public float ratio { get; set; }

        public GearJoint()
        {
            AddAnchor();
            AddAnchor();
            ratio = 1.0f;
        }

        public override Box2D.XNA.JointDef GetJointDef()
        {
            Box2D.XNA.Joint jA = GetJoint(Anchors[0].Target);
            Box2D.XNA.Joint jB = GetJoint(Anchors[1].Target);

            if (jA == null || jB == null) return null;

            Box2D.XNA.Body bA = jA.GetBodyB();
            Box2D.XNA.Body bB = jB.GetBodyB();

            if (bA == null || bB == null) return null;

            var Def = new Box2D.XNA.GearJointDef();
            Def.bodyA = bA;
            Def.bodyB = bB;
            Def.joint1 = jA;
            Def.joint2 = jB;
            Def.ratio = ratio;

            return Def;
        }
    }
}
